//多核处理，进程之间用IPC通信
var cluster = require('cluster');
//取cpu核数
var cpuNums = require('os').cpus().length;


//放在client.js 目前有问题，启动多个client.js进程，但只执行第一个。
Client.prototype.cluster =function () {
    if (cluster.isMaster) {
        console.log('[master] ' + "start master...");

        for (var ii = 0; ii < 3; ii++) { //总核数为1+ii的核数，这里代表3
            var wr =cluster.fork();
            wr.send('[master]'+ '广播worker'+wr.id)
        }
        cluster.on('listening',function (worker,address) {
            console.log('listening: worker ' + worker.process.pid +', Address: '+address.address+":"+address.port);
        });
        //关闭clients后释放所有核的client
        cluster.on('exit', function (worker, code, signal) {
            console.log('works' + worker.process.pid + 'died');
         });
    }else if (cluster.isWorker) {
        console.log('[worker] ' + "调用 不同worker ..." + cluster.worker.id);
        //替换成执行机器人程序  robot.run()
    }
}